Xbasic

COUNT Function

Syntax

Record_Count as N = count(A subexpr[,G over[,G each])

Arguments

subexpr

Any valid expression that includes a field or a combination of fields from the current table or set that specifies what you want to count. You can also specify a constant value, such as 0 or 1. Any type

over

Optional. When to use the function (instead of on every record).

each

Optional. When to reset the value produced by the function to 0 (instead at the end of all records). Get the count of subexpression over group 'over' sampled each group 'each'. The Group and Sub_Group are optional parameters that define the range of records to summarize, and may or may not be required, depending upon the context of the summary calculation. Possible values for GRP ->Group and GRP ->Sub Group include:

GRAND (all records)
The name of the current table.
The name of a table in the current set.
The name of a grouping level that is defined in a report layout.
DETAIL (over the records in the detail section)

Description

COUNT() returns the number of records in a group of records.

Discussion

COUNT() is equally valid in a calculated field on a form. COUNT() can be used in reports, and on forms to summarize data across multiple records. For example, to count the line-items in an invoice set, the GRP ->Group parameter might be GRP ->INVOICE and the GRP >Sub_Group parameter GRP >INV_ITEM. This means the summary operation includes only those child records in INV_ITEM related to the current parent record in the INVOICE table. To summarize all the records in a table or set, use the name GRAND as the Group name. The Group GRP->GRAND and Sub_Group GRP ->INV_ITEM produce a summary result based on all invoices. This function is a report writer function, not intended for table level field rules or other expressions. While the function may perform in some areas outside of the report writer, its use there is not supported.

Example

Assume that an invoicing set consists of two tables. One holds the invoices (INVOICE), and the other holds each invoice's line-items ( INV_ITEM ):

INVOICE
INV_NO
CUST_ID and INV_TOTAL
I100

C001 10.00

I101

C003 25.50

I102

C001 100.75

I103

C004 32.50

I104

C002 110.25

I105

C005 98.35

INVOICE is related to INV_ITEM through a one-to-many link on the INV_NO field. To determine the number of line-item records for a particular invoice, use the following expression:

? count(INV_ITEM->AMOUNT, GRP ->INVOICE, GRP ->INV_ITEM)
= 3, if the current INV_NO is "I102"

To determine the total number of INVOICE records, the expression is:

...put example here....? count(INVOICE->INV_NO, GRP ->INVOICE) 
              
             = 6

Note : This example is equivalent to using the RECNO() function.

Limitations

This function is a report writer function, not intended for table level field rules or other expressions.

See Also